home *** CD-ROM | disk | FTP | other *** search
- ;void write_center_b(strg,col,row,length,ln_color,strg_color);
- ; unsigned char *strg,col,row,length,ln_color,strg_color;
-
- EXTRN _memory_model:byte
- EXTRN _video_page:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _write_center_b
- _write_center_b proc near
- push bp ;
- mov bp,sp ;set stack frame
- push di ;
- push si ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: mov bh,_video_page ;set video page
- push ds ;save DS
- cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- lds si,dword ptr[bp+4] ;DS:SI pts to Strg
- inc bp ;add 2 to BP since dword ptr
- inc bp ;
- jmp short L00 ;
- L0: mov si,[bp+4] ;near case
- L00: sub dx,dx ;DX counts string length
- push si ;keep initial pointer position
- L000: cmp byte ptr[si],0 ;end of string?
- je L0000 ;jump if so
- inc si ;inc ptr
- inc dx ;inc counter
- jmp short L000 ;loop till end
- L0000: pop si ;restore ptr
- sub cx,cx ;
- mov cl,[bp+10] ;line length in CX
- mov byte ptr[bp+4],0 ;0 = no error
- sub cx,dx ;line len minus strg len
- cmp cx,0 ;check that 0 or more
- jge L1 ;jump ahead if so
- mov byte ptr[bp+4],1 ;1 = Length shorter than Strg
- sub cx,cx ;else remainder is 0
- L1: mov ax,cx ;copy in AX
- shr cx,1 ;now one half in CX
- sub ax,cx ;remainder in AX
- push ax ;push remainder for later
- push dx ;push strg len for later
- mov dl,[bp+6] ;Col in DL
- dec dl ;count from 0
- mov dh,[bp+8] ;Row in DH
- dec dh ;count from 0
- mov ah,2 ;function to set cursor
- int 10h ;set cursor to line
- mov bl,[bp+12] ;line attribute in BL
- jcxz L2 ;jmp if no spaces on left
- mov al,32 ;space char
- mov ah,9 ;BIOS func to write char
- int 10h ;draw spaces on left
- add dl,cl ;rightward cursor offset
- mov ah,2 ;function to set cursor
- int 10h ;reset the cursor
- L2: pop di ;string length counter
- or di,di ;null string?
- jz L4 ;jump ahead if so
- mov cx,1 ;print 1 char each time
- mov bl,[bp+14] ;string attribute in BL
- L3: mov ah,9 ;function to write char
- mov al,[si] ;get char from string
- inc si ;inc ptr for next time
- int 10h ;write the string
- mov ah,2 ;function to set cursor
- inc dl ;forward col count
- int 10h ;forward the cursor
- dec di ;dec character counter
- jnz L3 ;loop if not finished
- L4: pop cx ;right end spaces
- jcxz L5 ;quit if no spc on right
- mov al,32 ;space character
- mov bl,[bp+12] ;line attribute in BL
- mov ah,9 ;restore function number
- int 10h ;draw spaces on right
- L5: pop ds ;restore DS
- mov al,[bp+4] ;fetch _error_code
- mov _error_code,al ;set it
- pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _write_center_b endp
- _TEXT ENDS
- END